home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / amos / amosl0794.lzh / AMOSLIST / 000087_mentat@sefl.satelnet.org_Sat Jul 23 15:21:43 1994.msg < prev    next >
Internet Message Format  |  1994-08-01  |  3KB

  1. Received: from sefl.satelnet.org (satelnet.org) by nfs1.digex.net with SMTP id AA20704
  2.   (5.67b8/IDA-1.5 for <mcox@access.digex.net>); Sat, 23 Jul 1994 15:21:38 -0400
  3. Received: (from mentat@localhost) by sefl.satelnet.org (8.6.8.1/8.6.6) id PAA29227; Sat, 23 Jul 1994 15:21:21 -0400
  4. From: MenTaT - !Productions <mentat@sefl.satelnet.org>
  5. Message-Id: <199407231921.PAA29227@sefl.satelnet.org>
  6. Subject: Re: PIPEing
  7. To: mcox@access.digex.net (M D Cox)
  8. Date: Sat, 23 Jul 1994 15:21:19 -0400 (EDT)
  9. Cc: amos-list@access.digex.net
  10. In-Reply-To: <199407231643.AA22497@access1.digex.net> from "M D Cox" at Jul 23, 94 12:43:33 pm
  11. Content-Type: text
  12. Content-Length: 1944      
  13. Status: RO
  14.  
  15. > Has anyone ever written a program to accept STDIN or piping?  For
  16. > instance, if I wrote a program called WC that would count the number of words
  17. > and lines in a text file, would I be able to:
  18. > type textfile.txt > WC
  19. > or
  20. > type textfile.txt | WC
  21.  
  22. I'm not sure how the shell handles pipes - the easiest way to test it 
  23. would be to try it!
  24.  
  25. > I know i can do: WC textfile.txt, but then could I do:
  26. > WC textfile.txt > result.txt
  27.  
  28. Only if WC directed its output to the current shell window, which under 
  29. AMOS is hard to do.  You could be sneaky, and use a different 
  30. metacharacter, maybe @ or something else that isn't used, and get the 
  31. AMOS program to redirect it, but it's not a very good solution...  For 
  32. this kind of thing you're better off using C.
  33.  
  34. > with result.txt being created and containing the output of WC?
  35. > If anyone is familiar with programs like AWK or GREP, help me out if you
  36. > can, please!  :)
  37.  
  38. Here's a nice awk program...  (Dunno if it works in GNU awk, but it works 
  39. in System V...)
  40.  
  41. awk '
  42. FILENAME != prevfile {    # new file
  43.     NR = 1                # reset line number
  44.     prevfile = FILENAME
  45. }
  46. NF > 0 {
  47.     if ($1 == lastword)
  48.         printf "double %s, file %s, line %d\n",$1,FILENAME,NR
  49.     for (i = 2; i <= NF; i++)
  50.         if ($i == $(i-1))
  51.             printf "double %s, file %s, line %d\n",$i,FILENAME,NR
  52.     if (NF > 0)
  53.         lastword = $NF
  54. }' $*
  55.  
  56. It looks for pairs of identical adjacent words...  Kinda nifty. :)  (And 
  57. you can pipe it.  Not that this helps you at all. :)
  58.  
  59. I don't think AMOS was really ever designed for running from a shell, so 
  60. while there probably IS a way of piping and redirecting input and output, 
  61. C would be a lot easier.  (What am I saying?  C EASY? :)
  62.  
  63. Any awk/grep questions, just ask! :)  (And here's something nice - search 
  64. for users with no password an a *NIX machine :
  65.  
  66. grep '^[^:]*::' /etc/passwd
  67.  
  68. Not that I condone this sort of activity... :)
  69.  
  70.